<template>   
    <el-container class="home-container">
        <el-header>
            <div>
                <span>医疗器械后台管理系统</span>
            </div>
            <el-dropdown>
            <el-button type="primary" icon="el-icon-s-custom" circle></el-button>
            <el-dropdown-menu slot="dropdown">
                <el-dropdown-item icon="el-icon-user"><router-link :to ="'/welcome'" class="rl"> {{username}}</router-link></el-dropdown-item>
                <el-dropdown-item icon="el-icon-edit-outline"><router-link :to ="'/profile'" class="rl">修改密码</router-link></el-dropdown-item>
                <el-dropdown-item icon="el-icon-error"><el-link type="info" @click="logout" :underline="false">安全退出</el-link></el-dropdown-item>
            
            </el-dropdown-menu>
            </el-dropdown>
        </el-header>     
    <el-container> 
        <el-aside :width="isCollapse ? '64px':'200px'">
            <!-- 侧边栏 -->
            <div class="toggle-button" @click="toggleCollapse">|||</div>
            <el-menu default-active="1-4-1" class="el-menu-vertical-demo" :collapse="isCollapse" :router="true" :collapse-transition="true"
                background-color="#324157" text-color="#F1F1F1">
                <el-menu-item index="welcome" >
                    <i class="el-icon-s-home"></i>
                    <span slot="title" >系统首页</span>
                </el-menu-item>
                <el-menu-item index="datamanage" >
                    <i class="el-icon-s-data"></i>
                    <span slot="title">数据管理</span>
                </el-menu-item>
                <!-- <el-menu-item index="welcome" >
                    <i class="el-icon-info"></i>
                    <span slot="title" >信息管理</span>
                </el-menu-item> -->
            </el-menu>
        </el-aside>
        <!-- 主窗口 -->
        <el-main>
            <router-view></router-view>
        </el-main>
    </el-container>
    </el-container>
</template>

<script>
import { logoutApi } from '@/api/index'
import { removeToken,removeUserName,removeType } from '@/utils/auth'
import { resetRouter } from '@/router/index'
export default {
    methods:{
        logout(){
            logoutApi().then(()=>{
                this.$message.success("退出成功")
                this.$router.push("/login");//回到首页
                resetRouter()
                removeToken()
                removeUserName()
                removeType()
            })
            
        },
        toggleCollapse(){
            this.isCollapse=!this.isCollapse;
        }
    },
    
    data() {
      return {
        isCollapse: false,
        activePath:'/welcome',  //默认路径  
        username: window.sessionStorage.getItem("username"),
      };
    },
    computed:{
        getUserInfo(){
            let userinfo = this.$store.state.userinfo
            if(Object.keys(userinfo).length === 0){
                this.$store.dispatch('getUserInfo')
            }
        }
    }
}

</script>

<style lang='less' scoped>
.el-aside {
    background-color: #324157;
    color: #f1f1f1;
    text-align: center;
    .el-menu{
        border-right: none;
    }
  }
.el-main {
    background-color: #F1F1F1;
    color: #f1f1f1;
    text-align: center;
  }
  //布局器样式
.home-container{
    height: 100%;
}
.el-header{
    background-color: #253041;//#80EADC  #96b7e2
    display: flex;
    justify-content: space-between;
    padding-left: 0%;
    align-items: center;
    color: #fff;
    font-size: 20px;
    >div{
        display: flex;
        align-items: center;
        span{
            margin-left: 15px;
        }
    }
}
 .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
    background-color:#324157;
 

  }
.toggle-button{
    background-color: #324157;
    font-size: 10px;
    line-height: 24px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    cursor: pointer;
    height: 30px;
}
.rl {
    color: #606266;
    text-decoration: none;
}
.rl:hover {
    color: #7CC9FF;
    text-decoration: none;
}

</style>